home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / RAYTRACE.ZIP / HTASM.BAK < prev    next >
Encoding:
Text File  |  1994-06-11  |  5.6 KB  |  185 lines

  1. ; Assembler portion of Height Mapping test
  2. ; Started: 06/05/96
  3. ; Author: Lary Myers (based on original code by Leo Sutic)
  4. ; Module: HTASM.ASM
  5.  
  6.     IDEAL
  7.     JUMPS
  8.     P386
  9.     P387
  10.  
  11.  
  12.     MASM
  13.     .MODEL FLAT
  14.     .CODE
  15.     IDEAL
  16.  
  17.     extrn   _OffsetTable:word
  18.     extrn   _Buffer:dword
  19.     extrn   _Color:dword
  20.     extrn   _World:dword
  21.     extrn   _USERX:word
  22.     extrn   _USERY:word
  23.     extrn   _xPosns:word
  24.     extrn   _yPosns:word
  25.     extrn   _startpostable:word
  26.     extrn   _RangeTable:dword
  27.     extrn   _UserAlt:word
  28.     extrn   _Used:byte
  29.     extrn   _CurrentColumn:dword
  30.     extrn   _CurrentAngle:dword
  31.     extrn   _HighRow:dword
  32.     extrn   _OldPos:dword
  33.     extrn   _CurrentColor:byte
  34.  
  35.  
  36.     public  CopyVertical_
  37.     public  FillLinearBuffer_
  38.     public  FillUsedBuffer_
  39.  
  40. ;==============================================================================
  41. ; Copy a linear buffer to a vertical column of a video buffer
  42. ;==============================================================================
  43. proc    CopyVertical_ near
  44.     mov     eax,[_HighRow]  ; Pick up the starting row to draw
  45.     cmp     eax,200         ; If at the bottom of the screen
  46.     jae     noCopy          ; then get out now
  47.  
  48.     push    ebx
  49.     push    ecx
  50.  
  51.     push    esi
  52.     push    edi
  53.  
  54.     mov     edi,[_Buffer]               ; Buffer to draw into
  55.     movzx   ebx,[_OffsetTable+eax*2]    ; Pre-calculated video offset
  56.     add     edi,ebx
  57.     add     edi,[_CurrentColumn]        ; Display column to start with
  58.  
  59.     mov     esi,offset _Used            ; Buffer to get data from
  60.     add     esi,eax                     ; Plus the start row
  61.  
  62.     mov     ecx,200                     ; Total rows that can be drawn
  63.     sub     ecx,eax                     ; Minus our starting row
  64.     mov     ebx,320                     ; Amount to skip for each row
  65.  
  66. cvLoop:
  67.     mov     al,[esi]                    ; Current pixel
  68.     mov     ah,al                       ; Setup to copy to columns at once
  69.     mov     [edi],ax
  70.     inc     esi                         ; Next row of source buffer
  71.     add     edi,ebx                     ; Next row of video buffer
  72.     dec     ecx
  73.     jnz     cvLoop
  74.  
  75.     pop     edi
  76.     pop     esi
  77.  
  78.     pop     ecx
  79.     pop     ebx
  80.  
  81. noCopy:
  82.     ret
  83.     endp
  84.  
  85.  
  86. ;==============================================================================
  87. ; void FillLinearBuffer(short startpos,short i);
  88. ;==============================================================================
  89. proc    FillLinearBuffer_
  90.  
  91.     cmp     eax,[_OldPos]       ; Are we beyond the last remembered row?
  92.     jle     noFill              ; Nope, get out now
  93.     cmp     eax,0               ; Are we in bounds for the screen?
  94.     jle     noFill              ; Nope
  95.     cmp     eax,200             ; Check if beyond last row
  96.     jge     noFill              ; Get out if so
  97.  
  98.     push    ebx
  99.     push    ecx
  100.     push    edx
  101.     push    edi
  102.  
  103.     mov     ebx,[_OldPos]
  104.     cmp     ebx,200             ; Is last remembered row out of bounds?
  105.     jge     nfDone              ; Yes, getout
  106.  
  107.     cmp     dx,10               ; Is length near the bottom of the screen?
  108.     jge     short nfLarger      ; Not yet
  109.  
  110.     mov     ecx,200
  111.     sub     ecx,ebx             ; Get 200 - OldPos for number of rows
  112.     mov     eax,199             ; and set our starting row at bottom of screen
  113.     jmp     short nfDoFill      ; then continue with the fill
  114.  
  115.  
  116. nfLarger:
  117.     mov     ecx,eax             ; Get our starting row
  118.     sub     ecx,ebx             ; Minus last remembered row
  119.  
  120. nfDoFill:
  121.     sub     eax,ecx             ; Subtract number of rows from starting row
  122.     jnc     short nfNotNegative ; Didn't go above top
  123.  
  124.     add     ecx,eax             ; Else adjust the number of rows
  125.     xor     eax,eax             ; And set our starting row at top
  126.  
  127. nfNotNegative:
  128.     cmp     eax,[_HighRow]      ; Keep our highest row used updated
  129.     jge     short nfNotLess     ; Nope, not less than highest
  130.     mov     [_HighRow],eax      ; Else save current high row
  131.  
  132. nfNotLess:
  133.     mov     edi,offset _Used    ; Get our linear buffer
  134.     add     edi,eax             ; Add in the row we are going to start with
  135.  
  136.     mov     al,[_CurrentColor]  ; Get the color we want to use
  137.     mov     ah,al
  138.     mov     bx,ax               ; Hold onto it for a second
  139.     shl     eax,16              ; Move to the upper end
  140.     mov     ax,bx               ; Now eax contains 32 bit of color
  141.  
  142.     mov     ebx,ecx
  143.     shr     ecx,2               ; Divide length by four
  144.     rep     stosd               ; and blast in (sort of) 4 bytes at a time
  145.     and     ebx,3               ; get the remaining bytes to copy
  146.     mov     ecx,ebx
  147.     rep     stosb               ; and store them as bytes
  148.  
  149. nfDone:
  150.     pop     edi
  151.     pop     edx
  152.     pop     ecx
  153.     pop     ebx
  154.  
  155.  
  156. noFill:
  157.     ret
  158.     endp
  159.  
  160. ;==============================================================================
  161. ;
  162. ;==============================================================================
  163. proc FillUsedBuffer_ near
  164.     push    ecx
  165.     push    edi
  166.     mov     al,[_CurrentColor]
  167.     mov     ah,al               ; Put color into AX
  168.     mov     cx,ax               ; Hold onto it for a second
  169.     shl     eax,16              ; Move color to upper 16 bits
  170.     mov     ax,cx               ; And then fill lower 16 bits again
  171.     mov     edi,offset _Used
  172.     add     edi,100             ; Start 100 bytes into buffer
  173.  
  174.     mov     ecx,25              ; Fill 25 * 4 = 100 bytes of the buffer
  175.     rep     stosd
  176.  
  177.     pop     edi
  178.     pop     ecx
  179.     ret
  180.     endp
  181.  
  182.  
  183.     end
  184.  
  185.